/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Aptech.JavaXML.DOMValidator;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import nu.xom.Builder;
import nu.xom.Nodes;
import nux.xom.xquery.XQueryUtil;
import nu.xom.Document;

/**
 *
 * @author thanhtq
 */
public class ReadSurvey {


    public List<Survey> readSurvey(String path){

        List<Survey> surveys = new ArrayList<Survey>();
        Survey survey;
        try
        {
        Document doc = new Builder().build(new File(path));
        Nodes nodes = XQueryUtil.xquery(doc,"//Survey/category");
            for (int i = 0; i < nodes.size(); i++) {
                survey = new Survey();
                survey.setIdSurvey(nodes.get(i).query("@id").get(0).getValue());
                survey.setContentSurvey(nodes.get(i).query("content").get(0).getValue());
                survey.setCommenSurvey(nodes.get(i).query("comment").get(0).getValue());
                surveys.add(survey);
            }
        }catch(Exception ex){
        ex.printStackTrace();
        }
        return surveys;
    }
}
